import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";

export const Layout = () => import("@/layout/index.vue");

// 静态路由
export const constantRoutes: RouteRecordRaw[] = [
  {
    path: "/redirect",
    component: Layout,
    meta: { hidden: true },
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/redirect/index.vue"),
      },
    ],
  },

  {
    path: "/login",
    component: () => import("@/views/login/index.vue"),
    meta: { hidden: true },
  },

  {
    path: "/",
    name: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        component: () => import("@/views/dashboard/index.vue"),
        name: "Dashboard", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
        // https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        meta: {
          title: "dashboard",
          icon: "homepage",
          affix: true,
          keepAlive: true,
          alwaysShow: false,
        },
      },
      {
        path: "401",
        component: () => import("@/views/error-page/401.vue"),
        meta: { hidden: true },
      },
      {
        path: "404",
        component: () => import("@/views/error-page/404.vue"),
        meta: { hidden: true },
      },
    ],
  },
  {
     path: '/merchant',
     component: Layout,
     redirect: '/merchant/list',
     name: 'merchant',
     meta: {title: '商户管理', icon: 'captcha'},
     children: [
         {
             path: 'list',
             component: () => import('@/views/merchant/list/index.vue'),
             name: 'mchList',
             meta: {title: '商户列表'},
         },
         {
             path: 'history',
             component: () => import('@/views/merchant/history/index.vue'),
             name: 'mchHistory',
             meta: {title: '资金流水'},
         },
     ]
  },
  {
    path: '/agent',
    component: Layout,
    redirect: '/agent/list',
    name: 'agent',
    meta: {title: '代理管理', icon: 'cascader'},
    children: [
      {
        path: 'list',
        component: () => import('@/views/agent/list/index.vue'),
        name: 'agentList',
        meta: {title: '代理列表'},
      },
      {
        path: 'history',
        component: () => import('@/views/agent/history/index.vue'),
        name: 'agentHistory',
        meta: {title: '资金流水'},
      },
    ]
  },
  {
    path: '/config/pay',
    component: Layout,
    redirect: '/config/pay',
    name: 'configPay',
    meta: {title: '支付通道管理', icon: 'icon'},
    children: [
      {
        path: 'channel',
        component: () => import('@/views/config/pay/channel/index.vue'),
        name: 'configPayChannel',
        meta: {title: '上游支付通道'},
      },
      {
        path: 'product',
        component: () => import('@/views/config/pay/product/index.vue'),
        name: 'configPayProduct',
        meta: {title: '商户支付产品'},
      },
      {
        path: 'notify',
        component: () => import('@/views/config/pay/notify/index.vue'),
        name: 'configPayNotify',
        meta: {title: '支付通道回调'},
      },
    ]
  },
  {
    path: '/config/agentpay',
    component: Layout,
    redirect: '/config/agentpay',
    name: 'configAgentpay',
    meta: {title: '代付通道管理', icon: 'menu'},
    children: [
      {
        path: 'channel',
        component: () => import('@/views/config/agentpay/channel/index.vue'),
        name: 'configAgentpayChannel',
        meta: {title: '上游支付通道'},
      },
      {
        path: 'product',
        component: () => import('@/views/config/agentpay/product/index.vue'),
        name: 'configAgentpayProduct',
        meta: {title: '商户支付产品'},
      },
      {
        path: 'notify',
        component: () => import('@/views/config/agentpay/notify/index.vue'),
        name: 'configAgentpayNotify',
        meta: {title: '支付通道回调'},
      },
    ]
  },
  {
    path: '/order',
    component: Layout,
    redirect: '/order/pay',
    name: 'order',
    meta: {title: '支付订单', icon: 'peoples'},
    children: [
      {
        path: 'pay',
        component: () => import('@/views/order/pay/index.vue'),
        name: 'orderPay',
        meta: {title: '全部订单'},
      },
      {
        path: 'exception',
        component: () => import('@/views/order/exception/index.vue'),
        name: 'orderException',
        meta: {title: '异常订单'},
      },
    ]
  },
  {
    path: '/agentpay',
    component: Layout,
    redirect: '/agentpay/pay',
    name: 'agentpay',
    meta: {title: '代付订单', icon: 'tree'},
    children: [
      {
        path: 'pay',
        component: () => import('@/views/agentpay/pay/index.vue'),
        name: 'agentpayPay',
        meta: {title: '全部订单'},
      },
      {
        path: 'exception',
        component: () => import('@/views/agentpay/exception/index.vue'),
        name: 'agentpayException',
        meta: {title: '异常订单'},
      },
      {
        path: 'blacklist',
        component: () => import('@/views/agentpay/blacklist/index.vue'),
        name: 'agentpayBlacklist',
        meta: {title: '代付黑名单'},
      },
    ]
  },
  {
    path: '/statistic',
    component: Layout,
    redirect: '/statistic/daily_profit',
    name: 'statistic',
    meta: {title: '数据统计', icon: 'system'},
    children: [
      {
        path: 'plat_daily_profit',
        component: () => import('@/views/data/plat_daily_profit/index.vue'),
        name: 'plat_daily_profit_index',
        meta: {title: '平台分润日统计'},
      },
      {
        path: 'agent_daily_profit',
        component: () => import('@/views/data/agent_daily_profit/index.vue'),
        name: 'agent_daily_profit_index',
        meta: {title: '代理分润日统计'},
      },
      {
        path: 'mch_daily_profit',
        component: () => import('@/views/data/mch_daily_profit/index.vue'),
        name: 'mch_daily_profit_index',
        meta: {title: '商户支付日统计'},
      },
      {
        path: 'agent_top',
        component: () => import('@/views/data/agent_top/index.vue'),
        name: 'agent_top_index',
        meta: {title: '代理分润排行'},
      },
      {
        path: 'mch_top',
        component: () => import('@/views/data/mch_top/index.vue'),
        name: 'mch_top_index',
        meta: {title: '商户支付排行'},
      },
      {
        path: 'payOrder_successRate',
        component: () => import('@/views/data/payOrder_successRate/index.vue'),
        name: 'payOrder_successRate_index',
        meta: {title: '支付成功率统计'},
      },
      {
        path: 'product',
        component: () => import('@/views/data/product/index.vue'),
        name: 'product_index',
        meta: {title: '支付产品统计'},
      },
      {
        path: 'passage',
        component: () => import('@/views/data/passage/index.vue'),
        name: 'passage_index',
        meta: {title: '支付通道统计'},
      },
    ]
  },
  {
    path: '/log',
    component: Layout,
    redirect: '/log/merchant',
    name: 'log',
    meta: {title: '操作日志', icon: 'security'},
    children: [
      {
        path: 'merchant',
        component: () => import('@/views/log/merchant/index.vue'),
        name: 'logMerchant',
        meta: {title: '商户登录日志'},
      },
      {
        path: 'agent',
        component: () => import('@/views/log/agent/index.vue'),
        name: 'logAgent',
        meta: {title: '代理登录日志'},
      },
      {
        path: 'admin',
        component: () => import('@/views/log/admin/list/index.vue'),
        name: 'logAdmin',
        meta: {title: '管理员登录日志'},
      },
      {
        path: 'opertaion',
        component: () => import('@/views/log/admin/opertaion/index.vue'),
        name: 'logOpertaion',
        meta: {title: '管理员操作日志'},
      },
    ]
  },
/*   {
    path: '/robot',
    component: Layout,
    redirect: '/robot/index',
    name: 'robotIndex',
    meta: {title: '机器人助手', icon: 'shrink'},
    children: [
      {
        path: 'index',
        component: () => import('@/views/robot/index/index.vue'),
        name: 'robotIndex',
        meta: {title: '机器人管理'},
      },
      {
        path: 'user',
        component: () => import('@/views/robot/user/index.vue'),
        name: 'robotUser',
        meta: {title: '用户管理'},
      },
      {
        path: 'log',
        component: () => import('@/views/robot/log/index.vue'),
        name: 'robotLog',
        meta: {title: '操作日志'},
      },
    ]
  }, */
  {
    path: '/sys',
    component: Layout,
    redirect: '/sys/config',
    name: 'sys',
    meta: {title: '系统管理', icon: 'role'},
    children: [
      {
        path: 'admin',
        component: () => import('@/views/sys/admin/index.vue'),
        name: 'sysAdmin',
        meta: {title: '管理员信息'},
      },
      {
        path: 'role',
        component: () => import('@/views/sys/role/index.vue'),
        name: 'sysRole',
        meta: {title: '角色管理'},
      },
      {
        path: 'config',
        component: () => import('@/views/sys/config/index.vue'),
        name: 'sysConfig',
        meta: {title: '系统配置'},
      },
      {
        path: 'robot',
        component: () => import('@/views/sys/robot/index.vue'),
        name: 'sysIp_admin',
        meta: {title: '机器人助手'},
      },
      {
        path: 'message',
        component: () => import('@/views/sys/message/index.vue'),
        name: 'sysMessage',
        meta: {title: '消息管理'},
      },
    ]
  },
  {
    path: '/tools',
    component: Layout,
    redirect: '/tools/database',
    name: 'tools',
    meta: {title: '系统工具', icon: 'redis'},
    children: [
      {
        path: 'database',
        component: () => import('@/views/tools/database/index.vue'),
        name: 'toolsDatabase',
        meta: {title: '数据库看板'},
      },
      {
        path: 'cache',
        component: () => import('@/views/tools/cache/index.vue'),
        name: 'toolsCache',
        meta: {title: '缓存看板'},
      },
    ]
  },

];

/**
 * 创建路由
 */
const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoutes as RouteRecordRaw[],
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 }),
});

/**
 * 重置路由
 */
export function resetRouter() {
  router.replace({ path: "/login" });
}

export default router;
